<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- #BeginTemplate "../../../openslp.dwt" -->

<!--
    
    Pristine 1.0
    
    Design copyright Matt Dibb 2006
    www.mdibb.net

    Please feel free to use and modify this template for use on your site.  I dont mind
    if you use it for your personal site or a commercial site, but I do insist that it is
    not sold or given away in some "50,000 Templates!" package or something like that.

-->

    <head profile="http://www.w3.org/2005/10/profile">
        <meta http-equiv="Content-Language" content="en-gb" />
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
        <link rel="stylesheet" type="text/css" href="../../../site.css" />
        <link rel="stylesheet" type="text/css" href="../../../print.css" media="print" />
        <link rel="alternate" type="application/rss+xml" title="OpenSLP&#8230;Recent Activity" href="http://www.sourceforge.net/export/rss2_keepsake.php?group_id=1730" />
        <link rel="alternate" type="application/rss+xml" title="OpenSLP&#8230;News" href="http://www.sourceforge.net/export/rss2_projnews.php?group_id=1730" />
        <link rel="alternate" type="application/rss+xml" title="OpenSLP&#8230;File Releases" href="http://www.sourceforge.net/api/file/index/project-id/1730/mtime/desc/limit/20/rss" />
        <link rel="alternate" type="application/rss+xml" title="OpenSLP&#8230;Reviews" href="http://www.sourceforge.net/projects/openslp/reviews_feed.rss" />
		<link rel="shortcut icon" href="../../../images/openslp_favicon_256color_48px.ico" />
        <!-- #BeginEditable "Page%20Style%20and%20Scripts" -->
	    <!-- #EndEditable -->
        <!-- #BeginEditable "Page%20Title" -->
  <title>OpenSLP Programmers Guide - SLPReg()</title>
	    <!-- #EndEditable -->
    </head>
    <body>
        <div id="content">
            <div id="header">
            	<a href="http://openslp.org/">
				<img src="../../../images/openslp_logo_web_color_150px.jpg" alt="" /></a>
            </div>
            <div id="body">
                <!-- #BeginEditable "Left%20Navigation%20-%20Context%20Specific" -->

                <!-- #EndEditable -->
                <div id="links">
                    <p><a href="../../../index.html">About</a><br/>
                       what is openslp</p>
                    <p><a href="../../../download.html">Download</a><br/>
                       how to get openslp</p>
                    <p><a href="../../../contribute.html">Contribute</a><br/>
                       how to help out</p>
                    <p><a href="../../../documentation.html">Documentation</a><br/>
                       how to find out more</p>
                    <p><a href="../../../credits.html">Credits</a><br/>
                       who to blame</p>
                    <p><a href="http://sourceforge.net/projects/openslp"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=1730&amp;type=2" alt="Get OpenSLP at SourceForge.net. Fast, secure and Free Open Source software downloads"/></a></p>
                </div>

                <div id="main">
                <!-- #BeginEditable "Page%20Content" -->

<h2>SLPReg<br />
<span id="breadcrumbs"><a href="index.html">OpenSLP Programmer's Guide</a> &raquo; Service Registration Functions &raquo; <a href="SLPReg.html">SLPReg</a></span></h2>

<h3>Declaration</h3>

<pre>#include &lt;slp.h&gt;

<a href="SLPTypes.html#SLPEXP">SLPEXP</a> <a href="SLPError.html">SLPError</a> <a href="SLPTypes.html#SLPAPI">SLPAPI</a> SLPReg(
    <a href="SLPTypes.html#SLPHandle">SLPHandle</a>      <a href="#hslp">hslp</a>,
    const char *   <a href="#srvurl">srvurl</a>,
    unsigned short <a href="#lifetime">lifetime</a>,
    const char *   <a href="#srvtype">srvtype</a>,
    const char *   <a href="#attrs">attrs</a>,
    <a href="SLPTypes.html#SLPBoolean">SLPBoolean</a>     <a href="#fresh">fresh</a>,
    <a href="SLPRegReport.html">SLPRegReport</a>   <a href="#callback">callback</a>,
    void *         <a href="#cookie">cookie</a>);
</pre>

<h3>Description</h3>

<p>Registers the URL in <tt>srvurl</tt> having the lifetime <tt>
lifetime</tt>
with the attribute list in <tt>attrs</tt>. The <tt>attrs</tt> 
list is a comma separated list of attribute assignments in 
the wire format (including escaping of reserved characters). 
The <tt>lifetime</tt> parameter must be nonzero and less 
than or equal to
<tt><a href="SLPTypes.html#SLPURLLifetime">SLP_LIFETIME_MAXIMUM</a></tt>. If the
<tt>fresh</tt> flag is <tt>SLP_TRUE</tt>, then the registration 
is new (the SLP protocol FRESH flag is set) and the 
registration replaces any existing registrations. The <tt>
srvtype</tt> parameter is a service type name and can be 
included for service URLs that are not in the service: 
scheme. If the URL is in the service: scheme, the <tt>
srvtype</tt>
parameter is ignored. If the fresh flag is <tt>SLP</tt>_FALSE, 
then an existing registration is updated. Registrations and 
updates take place in the language locale of the <tt>hslp</tt> 
handle.</p>

<h3>Parameters</h3>

<table nosave="" border="1" cellpadding="5">
  <tbody>
    <tr nosave="" valign="top">
      <td nosave=""><a name="hslp"></a><tt>hslp</tt></td>
      <td nosave="">The language specific <tt>SLPHandle</tt> on which to 
	  register the service.</td>
    </tr>
    <tr nosave="" valign="top">
      <td><a name="srvurl"></a><tt>srvurl</tt></td>
      <td nosave="">The service URL to register.&nbsp;  May not be the empty string.&nbsp; 
	  May not be NULL.&nbsp; Must conform to SLP Service URL syntax. <tt><a
 href="SLPError.html#INVALID_REGISTRATION">SLP_INVALID_REGISTRATION</a></tt>
	  will be returned if srvurl is not a SLP Service URL. See <a
 href="Syntax.html">Syntax</a>
	  for more information on Service URL syntax.</td>
    </tr>
    <tr nosave="" valign="top">
      <td nosave=""><a name="lifetime"></a><tt>lifetime</tt></td>
      <td nosave="">An unsigned short giving the lifetime of the service in 
	  seconds.&nbsp; The value must be an unsigned integer less than or equal to <tt><a
 href="SLPTypes.html#SLPURLLifetime">SLP_LIFETIME_MAXIMUM</a></tt>
	  and greater than zero.&nbsp; <i>If lifetime is set to <tt><a
 href="SLPTypes.html#SLPURLLifetime">SLP_LIFETIME_MAXIMUM</a></tt>, it will 
	  remain registered for the life of the calling process.</i></td>
    </tr>
    <tr nosave="" valign="top">
      <td><a name="srvtype"></a>srvtype</td>
      <td nosave="">This parameter is always ignored because the Service URL 
	  syntax required for the <tt>srvurl</tt> parameter encapsulates the 
	  service-type.&nbsp; See <a href="Syntax.html">Syntax</a> for more information 
	  on Service URL syntax.</td>
    </tr>
    <tr nosave="" valign="top">
      <td nosave=""><a name="attrs"></a>attrs</td>
      <td>A list of attribute assignment expressions for the attributes of the 
	  registered service.&nbsp; Use the empty string, &quot;&quot; for no attributes.&nbsp; Example: 
	  &quot;(attr1=val1),(attr2=val2),(attr3=val3)&quot;</td>
    </tr>
    <tr nosave="" valign="top">
      <td><a name="fresh"></a><tt>fresh</tt></td>
      <td nosave="">An SLPBoolean that is <tt>SLP_TRUE</tt> if the registration 
	  is new or <tt>SLP_FALSE</tt> for a re-registration.&nbsp; Currently, OpenSLP 
	  does not support incremental registrations.&nbsp; If <tt>fresh</tt> is
      <tt>SLP_FALSE</tt>, <tt>SLPReg()</tt>
	  will return <tt><a href="SLPError.html#SLP_NOT_IMPLEMENTED">
	  SLP_NOT_IMPLEMENTED</a></tt>.</td>
    </tr>
    <tr nosave="" valign="top">
      <td><a name="callback"></a><tt>callback</tt></td>
      <td nosave="">The address of an <tt><a href="SLPRegReport.html">
	  SLPRegReport</a></tt>
	  function that will be called to report the operation completion status.&nbsp; 
	  Man not be NULL. See <a href="Callbacks.html">Callbacks</a> for more 
	  information on how callbacks are used by the SLPAPI.</td>
    </tr>
    <tr nosave="" valign="top">
      <td nosave=""><a name="cookie"></a><tt>cookie</tt></td>
      <td nosave="">Pointer to memory that gets passed to the callback code.&nbsp; 
	  May be NULL.</td>
    </tr>
  </tbody>
</table>

<h3>Returns</h3>

<table nosave="" border="1">
  <tbody>
    <tr nosave="">
      <td nosave="">SLP_OK</td>
      <td>Indicates that the no error occurred during the operation.</td>
    </tr>
    <tr>
      <td>SLP_INVALID_REGISTRATION</td>
      <td>The deregistered service url does not conform to valid service url 
	  syntax.&nbsp; The service url being deregistered is not registered this means 
	  that either it was never registered via a call to SLPReg() or that the 
	  registration lifetime has expired.&nbsp;&nbsp; SLP_INVALID_REGISTRATION is commonly 
	  returned when an attempt is made to deregister a service that was 
	  registered by a call to SLPReg() on a different host.</td>
    </tr>
    <tr>
      <td>SLP_PARSE_ERROR</td>
      <td>The SLP message was rejected by a remote SLP agent. The API returns 
	  this error only when no information was retrieved, and at least one SA or 
	  DA indicated a protocol error. The data supplied through the API may be 
	  malformed or a may have been damaged in transit.</td>
    </tr>
    <tr>
      <td>SLP_AUTHENTICATION_ABSENT</td>
      <td>If the SLP framework supports authentication, this error arises when 
	  the UA or SA failed to send an authenticator for requests or 
	  registrations.</td>
    </tr>
    <tr>
      <td>SLP_AUTHENTICATION_FAILED</td>
      <td>If the SLP framework supports authentication, this error arises when a 
	  authentication on an SLP message failed.</td>
    </tr>
    <tr>
      <td>SLP_NETWORK_TIMED_OUT</td>
      <td>When no reply can be obtained in the time specified by the configured 
	  timeout interval for a unicast request, this error is returned.&nbsp; In other 
	  words, slpd is running, but something is wrong with it</td>
    </tr>
    <tr>
      <td>SLP_NETWORK_INIT_FAILED</td>
      <td>If the network cannot initialize properly, this error is returned. 
	  Will also be returned if an SA or DA agent (slpd) can not be contacted.&nbsp; 
	  slpd must be running in order to call SLPReg() or SLPDereg().</td>
    </tr>
    <tr>
      <td>SLP_MEMORY_ALLOC_FAILED&nbsp;</td>
      <td>Out of memory error</td>
    </tr>
    <tr>
      <td>SLP_PARAMETER_BAD</td>
      <td>If a parameter passed into a function is bad, this error is returned.</td>
    </tr>
    <tr>
      <td>SLP_NETWORK_ERROR</td>
      <td>The failure of networking during normal operations causes this error 
	  to be returned.&nbsp; In OpenSLP, this is the error you'll get if an underlying 
	  socket() call failed.</td>
    </tr>
    <tr>
      <td>SLP_INTERNAL_SYSTEM_ERROR</td>
      <td>A basic failure of the API causes this error to be returned. This 
	  occurs when a system call or library fails. The operation could not 
	  recover.</td>
    </tr>
    <tr>
      <td>SLP_HANDLE_IN_USE</td>
      <td>Callback functions are not permitted to recursively call into the API 
	  on the same SLPHandle, either directly or indirectly. If an attempt is 
	  made to do so, this error is returned from the called API function.</td>
    </tr>
    <tr>
      <td>SLP_BUFFER_OVERFLOW</td>
      <td> If the registered SLP message is larger than MTU size, this error is 
	  returned.</td>
    </tr>
  </tbody>
</table>

<p>Be aware, especially if the call is async, of error codes that may be passed 
to the SLPRegReport callback function.</p>

<h3>Status</h3>

<table nosave="" cellpadding="5">
  <tbody>
    <tr nosave="" valign="top">
      <td nosave="">OpenSLP 0.8.0</td>
      <td nosave="">Fully implemented as specified by RFC 2614</td>
    </tr>
  </tbody>
</table>

<br />
<h3>See Also</h3>

<p><a href="SLPDereg.html">SLPDeReg</a>, <a href="Syntax.html">Syntax</a>,
<a href="Callbacks.html">Callbacks</a></p>

<h3>Example Code</h3>

<pre>
  #include &lt;slp.h&gt;

  void MySLPRegReport(SLPHandle hslp, SLPError errcode, void* cookie)
  {
      /* return the error code in the cookie */
 
      *(SLPError*)cookie = errcode;
      
      /* You could do something else here like print out
       * the errcode, etc.  Remember, as a general rule,
       * do not try to do too much in a callback because
       * it is being executed by the same thread that is
       * reading slp packets from the wire.
       */
  }
  
  int main(int argc, char* argv[])
  {
      SLPError err;
      SLPError callbackerr;
      SLPHandle hslp;
      
      err = SLPOpen(&quot;en&quot;, SLP_FALSE, &amp;hslp);
 
      if (err != SLP_OK)
      {
          printf(&quot;Error opening slp handle %i\n&quot;, err);
          return err;
      }
      
      /* Register a service with SLP */
      err = SLPReg(
              hslp,
              &quot;service:myservice.myorg://hostname.domain.com:6672&quot;,
              SLP_LIFETIME_MAXIMUM,
              0,
              &quot;(public_key=......my_pgp_key.......)&quot;,
              SLP_TRUE,
              MySLPRegReport,
              &amp;callbackerr);

      /* err may contain an error code that occurred as the slp library
       * _prepared_ to make the call.
       */
      if (err != SLP_OK)
      {
          printf(&quot;Error registering service with slp %i\n&quot;, err);
          return err;
      }
      
      /* callbackerr may contain an error code (that was assigned through
       * the callback cookie) that occurred as slp packets were sent on
       * the wire.
       */
      if (callbackerr != SLP_OK)
      {
          printf(&quot;Error registering service with slp %i\n&quot;, callbackerr);
          return callbackerr;
      }
      
      /* Now that we're done using slp, close the slp handle */
      SLPClose(hslp);
      
      /* the rest of program */
  }
</pre>

<p id="breadcrumbs0">Maintained by: <a href="http://www.openslp.org/">openslp.org</a></p>

                <!-- #EndEditable -->
                </div>
            </div>

            <div id="footer">
                Copyright &copy; 2011 <a href="http://www.openslp.org/">openslp.org</a>. All Rights Reserved.<br/>
                Design by <a href="http://www.mdibb.net" title="Website of Matt Dibb">Matt Dibb</a>
                2006. <a href="http://jigsaw.w3.org/css-validator/check/referer" title="Validate CSS">CSS</a> 
                <a href="http://validator.w3.org/check/referer" title="Validate XHTML">XHTML</a>
                <br/>Courtesy of <a href="http://www.openwebdesign.org">Open Web Design</a>
                &amp; <a href="http://seo-services.us">seo</a>
            </div>
        </div>
    </body>
<!-- #EndTemplate -->
</html>
